<%@page import="java.awt.print.Printable"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>_${customer.customerName}_拣货车管理</title>
<script type="text/javascript">
  
  $(function() {
		$("#queryForm").validate(); 
  });
  
  //创建拣货车
  function createPickCar(){
       $("#btn_submit").attr("disabled",true); 
       
	   if( $("#inputForm").valid() ){
		      var carName=$("#carName").val().trim();
		      var stockNum=$("#stockNum").val().trim();
		      var customerCode=$("#customerCode").val().trim();
		      var warehouseCode=$("#warehouseCode").val().trim();
		      
		       $.ajax({
				type : 'post',
				url : '${ctx}/pickCar/ajaxCreatePickCar',
				data : {
					carName:carName,
					stockNum:stockNum,
					customerCode:customerCode,
					warehouseCode:warehouseCode
				},
				dataType : 'json',
				success : function(data) {
				    if(data==true){
				       $("#queryForm").submit();
				    }else{
				       alert("网络繁忙，请稍后重试...");
				    }
				    $("#btn_submit").attr("disabled",false); 
				
				},
				error : function() {
					alert("网络繁忙，请稍后重试...");
					 $("#btn_submit").attr("disabled",false); 
				}
			});
	      
	   }else{
	       $("#btn_submit").attr("disabled",false); 
	   }
  }
  
  //重设表单
  function formReset(){
    $("input[type=reset]").trigger("click");
  }
	      
	
  //打开创建拣货车窗体
  function openWin(){
	if( $("#queryForm").valid() ){
	    formReset();
		$("#btn_submit").attr("disabled",null);
		$("#inputForm").attr("action",'${ctx}/pickCar/createPickCar');
		$("#warehouseCode").val($("#_warehouseCode").val());
		$("#customerCode").val($("#_customerCode").val());
		$("#newPickCar").trigger("click");
		
	}
  }
  
  //删除
  function ajaxDeletePickCar(pickCarId){
     
     $.ajax({
			type : 'post',
			url : '${ctx}/pickCar/ajaxDeletePickCar',
			data : {
				pickCarId:pickCarId
			},
			dataType : 'json',
			success : function(data) {
			    if(data==true){
			       $("#queryForm").submit();
			    }else{
			       alert("网络繁忙，请稍后重试...");
			    }
			
			},
			error : function() {
				alert("网络繁忙，请稍后重试...");
			}
		});
  }
  
  //释放
  function ajaxFree(pickCarId){
     $.ajax({
			type : 'post',
			url : '${ctx}/pickCar/ajaxFree',
			data : {
				pickCarId:pickCarId
			},
			dataType : 'json',
			success : function(data) {
			    if(data.status=="success"){
			       $("#queryForm").submit();
			    }else if(data.status=="notFree"){
			       jAlert("拣货车无法释放，请确认是否有未完成任务.")
			    }else{
			       alert("网络繁忙，请稍后重试...");
			    }
			
			},
			error : function() {
				alert("网络繁忙，请稍后重试...");
			}
		});
  }
  
  //加载拣货车详细信息
  function ajaxLoadPickCarDetail(pickCarId){
     $("#stockInfo").html("");
     $.ajax({
			type : 'post',
			url : '${ctx}/pickCar/ajaxLoadPickCarDetail',
			data : {
				pickCarId:pickCarId
			},
			dataType : 'json',
			success : function(data) {
			   
			   var shelf=data.pickCar;
			   var stockList=data.stockList;
			   
			   $("#_carName").html(shelf["carName"]);
			   $("#_carCode").html(shelf["carCode"]);
			   $("#_stockNum").html(shelf["stockNum"]);
			   $("#_batchCode").html(shelf["batchCode"]);
			   $("#_taskCode").html(shelf["taskCode"]);
			   var status=shelf["status"];
			   if(status=='busy'){
			     $("#_status").html("<font color=red>使用中</font>");
			   }else if(status=='free'){
			     $("#_status").html("闲置中");
			   }
			   
			   var str="";
			   $.each(stockList,function(i){
			      var stock=stockList[i];
			      str+="<tr>"
			      str+="<td>"+(i+1)+"</td>";
			      str+="<td>"+stock.stockName+"</td>";
			      str+="<td>"+stock.stockCode+"</td>";
			      str+="<td>"+stock.orderno+"</td>";
			      str+="<td>"+stock.goodsNum+"</td>";
			      str+="<td>"+stock.goodsInfo+"</td>";
			      
			      var status=stock.status;
				  if(status=='busy'){
				      str+="<td><font color=red>使用中</font></td>";
				  }else if(status=='free'){
				      str+="<td>闲置中</td>";
				  }
			      
			      str+="</tr>";
			   });
			   $("#stockInfo").html(str);
			   
			
			},
			error : function() {
				alert("网络繁忙，请稍后重试...");
			}
		});
  }
  
  //init打印机
  function initPrinter(item) {
		//var indexLength = getPrinterCount();
		//var tempString = "";
		//for ( var i = 0; i < indexLength; i++) {
		//	var name = getPrinterName(i);
		//	tempString += "<option value='"+name+"'>" + name + "</option>";
		//}
		$("#printerNumber").html("打印编码(<font color=blue>" + item + "</font>)");
		$("#hiddenCode").val(item);
		//$("#printerBody").html(tempString);
		packFormPrinter("printerBody");
  }
  
  //打印
  function clickPrinter() {
		var code = $("#hiddenCode").val();
		var printName = $("#printerBody").val();
		printBarCode(printName, code);
  }
  
  function printBarCode(printName, taskName) {
		LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
		LODOP.PRINT_INIT(taskName);
		LODOP.SET_PRINT_PAGESIZE(1, 600, 320, "");
		LODOP.ADD_PRINT_BARCODE(25, 10, 200, 45, "128B", taskName);
		LODOP.SET_PRINT_STYLE("FontName","SimHei");
	    LODOP.SET_PRINT_STYLE("FontSize",25);
		LODOP.ADD_PRINT_TEXT(70, 30, 200,100,taskName);
		if (LODOP.SET_PRINTER_INDEXA(printName)) {
			LODOP.PRINT();
		}
  }
  

</script>
</head>

<body>
<section class="content">
<div class="row">
		<div class="col-md-12">

			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">搜索栏</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
		     
		     <form class="form-search" id="queryForm" method="post" action="${ctx}/pickCar/v2_queryPickCar">
			 	<div class="form-group row">
						<div class="col-sm-3">
							<div class="input-group col-sm-12">
			 	<label class="input-group-text">商家:</label>
				 <select  name="_customerCode"  id="_customerCode" value="${param._customerCode}"  class="form-control required" onchange="ajaxAreaGroup(this,'_warehouseCode');">
					<option value=""></option>
					<c:forEach items="${customerList}" var="customer">
						<option value="${customer.customerCode}"
						<c:if test="${param._customerCode eq customer.customerCode}">selected=selected</c:if>
						>${customer.customerName}</option>
					</c:forEach>
				</select>
			 	</div>
			 	</div>
			 	
			 	<div class="col-sm-3">
							<div class="input-group col-sm-12">
				<label class="input-group-text">仓库:</label>
				<select  name="_warehouseCode"  id="_warehouseCode" class="form-control required">
					<option value=""></option>
					<c:forEach items="${warehouseList}" var="w">
					   <option value="${w.groupCode}" 
					   <c:if test="${param._warehouseCode eq w.groupCode }">selected=selected</c:if>
					   >${w.groupName}</option>
				   </c:forEach>
				</select>
				</div>
				</div>
				<div class="col-sm-3">
							<div class="input-group col-sm-12">
			    <button class="btn btn-info" type="submit" style="margin-left: 10px;">搜索</button>
			    <a  data-toggle="modal" role="button" style="margin-left: 10px;" class="btn btn-info" onclick="openWin();" >添加拣货车</a>
			    <a href="#win_newPickCar" role="button" id="newPickCar" data-toggle="modal" style="display: none;"></a>
			    </div>
			    </div>
			    </div>
		    </form>
		    
	</div>
	</div>
	</div>
	</div>
	
	
	<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-list"></i>
					<h3 class="box-title">查询结果</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead><tr>					
			    <th style="width: 50px;">序号</th>
			    <th>商家</th>
			    <th>仓库</th>
			    <th>车名称</th>
			    <th>车编号</th>
			    <th>库位数</th>
			    <th>状态</th>
			    <th>操作</th>
			</tr></thead>
		<tbody>
		<c:forEach items="${pickCarList}" var="pickCar" varStatus="i">
			<tr>
			   <td>${i.count}</td>
			   <td>${pickCar.customer.customerName}</td>
			   <td>${pickCar.warehouse.groupName}</td>
			   <td>${pickCar.carName}</td>
			   <td>${pickCar.carCode}</td>
			   <td>${pickCar.stockNum}</td>
			   <td >
			     <c:if test="${pickCar.status eq 'free'}">空置中</c:if>
			     <c:if test="${pickCar.status eq 'busy'}"><font color=red>使用中</font></c:if>
			   </td>
			   <td>
			       <c:if test="${pickCar.status eq 'busy'}">
			          <%-- <button style="display: none;" class="btn btn-danger" onclick="ajaxFree('${pickCar.id}');">释放</button> --%>
			       	  <button class="btn btn-danger" onclick="ajaxFree('${pickCar.id}');">释放</button>
			       </c:if> 
			       
			       <c:if test="${pickCar.status eq 'free'}">
			          <button  class="btn btn-primary" onclick="ajaxDeletePickCar('${pickCar.id}');">删除</button>
			       </c:if> 
			       
			        <a href="#win_detail" data-toggle="modal" role="button" onclick="ajaxLoadPickCarDetail('${pickCar.id}');"  class="btn btn-primary" >查看详情</a>
			        <a href="#selextPrinter" role="button" data-toggle="modal" class="btn btn-primary" onclick="initPrinter('${pickCar.carCode}')">打印条码</a>
			   </td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	</div>
	</div>
	</div>
	</div>
	
	<!--拣货车  窗体 --> 
	<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" id="win_newPickCar" >
		<div class="modal-dialog">
		<div class="modal-content">
		<div class="modal-header">
			<h4>创建拣货车</h4>
		</div>
		
		<div class="modal-body">
		<form id="inputForm"  method="post" class="form-horizontal">
		   <fieldset>
				  <!-- 行1 -->
			          <div class="form-group row">
							<div class="col-sm-6">
								<div class="input-group col-sm-12">
								<label  class="input-group-text">车名称:</label>
								    <input type="text" id="carName" name="carName" class="input-long required" >
								    <input type="hidden" id="customerCode" name="customerCode" >
								    <input type="hidden" id="warehouseCode" name="warehouseCode" >
								    <input id="btn_reset" type="reset" style="display:none;" /> 
							</div>
			          </div>
			          <div class="col-sm-6">
							<div class="input-group col-sm-12">
								<label  class="input-group-text" >库位数:</label>
							    <input type="text" id="stockNum" name="stockNum" class="input-long required digits" >
						    </div>
					</div>
			      </div>
						     
			</fieldset>	 
			</form>
		</div>
		
		<div class="modal-footer bg-gray">
		    <button id="btn_submit" class="btn btn-primary" onclick="createPickCar();">确定创建</button>&nbsp;	 
			<button id="btn_cancel" class="btn" data-dismiss="modal" aria-hidden="true">返回</button>
		</div>
	</div>
	</div>
	</div>
	<!--详情 窗体 --> 
	<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" id="win_detail" >
		<div class="modal-dialog" style="width:830px; height:500px;">
		<div class="modal-content">
		<div class="modal-header">
		</div>
		
		<div class="modal-body" style=" width:800px; height:400px; overflow:auto;">
		  
		   <!-- 拣货车信息 -->
		   <table id="contentTable" class="table table-striped table-bordered table-condensed">
		        <thead>
					<th style="vertical-align: middle; color: white;" colspan="11" bgcolor="#8EB4CB">拣货车信息</th>
				</thead>
				<thead><tr>					
					    <th>车名称</th>
					    <th>车编号</th>
					    <th>规格</th>
					    <th>库位数</th>
					    <th>作业批次号</th>
					    <th>作业任务号</th>
					    <th>车状态</th>
					</tr></thead>
					<tr>
					   <td id="_carName"></td>
					   <td id="_carCode"></td>
					   <td id="_guige"></td>
					   <td id="_stockNum"></td>
					   <td id="_batchCode"></td>
					   <td id="_taskCode"></td>
					   <td id="_status"></td>
					</tr>
				</tbody>
			</table>
		   
		   <!-- 车位信息 -->
		   <table id="contentTable" class="table table-striped table-bordered table-condensed">
		        <thead>
					<th style="vertical-align: middle; color: white;" colspan="11" bgcolor="#8EB4CB">车位详情</th>
				</thead>
				<thead><tr>					
					    <th style="width: 50px;">序号</th>
					    <th>车位名称</th>
					    <th>车位编号</th>
					    <th>订单号</th>
					    <th>商品数量</th>
					    <th>商品信息</th>
					    <th>车位状态</th>
					</tr></thead>
				<tbody id="stockInfo" style="height: 200px;">
				</tbody>
			</table>
		
		</div>
		
		<div class="modal-footer bg-gray">
			<button id="btn_cancel" class="btn btn-primary" data-dismiss="modal" aria-hidden="true">确定</button>
		</div>
	</div>
	</div>
	</div>
	<!-- 打印条码窗体 -->
	<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" id="selextPrinter">
		 <div class="modal-dialog" style="width:1000">
		<div class="modal-content">
		 <div class="modal-header">
			  <h3 id="printerNumber">打印条码</h3>
		  </div>
			
		  <div class="modal-body" style="margin-left: 100px;">
			  <select id="printerBody" name="printerBody" style="width: 300px;"></select>
			   <input type="hidden" id="hiddenCode" name="hiddenCode">
		  </div>
			
		  <div class="modal-footer bg-gray">
			  <button class="btn btn-primary" data-dismiss="modal" aria-hidden="true" id="printer" onclick="clickPrinter()">开始打印</button>
			  <button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
		  </div>
		</div>
		</div>
	</div>
</section>
</body>
</html>
